import { ipcMain } from 'electron'
import { sqInsert, sqQuery, sqUpdate, sqDelete } from './index'

ipcMain.handle('password-list', async (event, data) => {
  return await sqQuery({
    sql: `
    SELECT t.*
    FROM password t
    WHERE projectId = ?`,
    params: [data.projectId]
  })
})

ipcMain.handle('password-add', async (event, data) => {
  for(const item of data.list){
    await sqInsert({ table: 'password', data: item })
  }
})

ipcMain.handle('password-update', async (event, data) => {
  await sqUpdate({ table: 'password', data: data, condition: `id = ${data.id}` })
})

ipcMain.handle('password-delete', async (event, data) => {
  await sqDelete({ table: 'password', condition: `id = ${data.id}` })
})
